package com.example.java.io;

import java.io.IOException;
import java.nio.CharBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;

public class MappedByteBufferTest {
    public static void main(String[] args) throws IOException {
        ///Users/xiaohongfei/Downloads/cys2.zip
        CharBuffer charBuffer = null;
        ClassLoader classLoader = MappedByteBufferTest.class.getClassLoader();
//        Path path = Paths.get(classLoader.getResource("log.txt").getPath());
        Path path = Paths.get("/Users/xiaohongfei/Downloads/cys2.zip");
        try (FileChannel fileChannel = FileChannel.open(path)) {
            MappedByteBuffer map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
            if (map != null) {
                charBuffer = Charset.forName("UTF-8").decode(map);
            }
            System.out.println(charBuffer);
        }

    }
}
